package chd.edu.spzx.manager.controller;

import chd.edu.spzx.manager.service.FileUploadService;
import chd.edu.spzx.model.vo.common.Result;
import chd.edu.spzx.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author Zhang Chaoliang
 * create 2023
 * 文件上传（头像）控制类
 */
@RestController
@RequestMapping("/admin/system")
public class FileUploadController {

    @Autowired
    private FileUploadService fileUploadService;

    /**
     * 文件上传方法
     * @param file 参数名字必须是file
     *             <input type="file" name="file"/>
     *             或者写成：@RequestParam(value = "file") MultipartFile multipartFile
     * @return
     */
    @PostMapping(value = "/fileUpload")
    public Result fileUploadService(MultipartFile file){
        //1.获得上传的文件
        //2.调用service的方法上传，返回minio路径
        String url = fileUploadService.upload(file);
        return Result.build(url, ResultCodeEnum.SUCCESS);
    }
}
